﻿using Hello.Api.Filters;
using Hello.Api.Orders.Contracts;
using MassTransit;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Hello.Api.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class OrdersController : ControllerBase
    {
        private readonly IRequestClient<VerifyOrder> requestClient;

        public OrdersController(IRequestClient<VerifyOrder> requestClient)
        {
            this.requestClient = requestClient;
        }
        [HttpGet]
        public async Task<IActionResult> GetOrder(int id)
        {
            var response = await requestClient.GetResponse<OrderResult, OrderNotFoundResult,Email>(
                new
                {
                    Id = id,
                    __Header_Promotion="some-promotional-discount-percent"//加上header

                });

            if (response.Is(out Response<OrderResult> order))
            {

                return Ok(order.Message);
            }
            if (response.Is(out Response<OrderNotFoundResult> orderNotFound))
            {
                return NotFound();
            }

            return BadRequest();
        }
    }
}
